package cn.edu.jnu.x2020101323;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    private BowlingGame game;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button calculate_button = this.findViewById(R.id.button);
        EditText Input = this.findViewById(R.id.input);
        TextView result = this.findViewById(R.id.result);

        game = new BowlingGame();

        calculate_button.setOnClickListener(new View.OnClickListener() {
            @SuppressLint("SetTextI18n")
            @Override
            public void onClick(View v) {
                String input_string = Input.getText().toString();
                String[] score_string = input_string.split(",");
                for(int i = 0; i < score_string.length; i++){
                    game.roll(Integer.parseInt(score_string[i]));
                }
                result.setText("total score is:"+game.score());
//                result.setTextSize(30);
            }
        });


    }
}